<html>
<head><meta charset="utf-8"><title>cc and arch-specific flags for specific source files · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html">cc and arch-specific flags for specific source files</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207043884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/207043884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#207043884">(Aug 15 2020 at 23:04)</a>:</h4>
<p>Using the <code>cc</code> crate, is there any way to specify a flag for a specific source file, without specifying it for any other source file?</p>



<a name="207043894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/207043894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#207043894">(Aug 15 2020 at 23:04)</a>:</h4>
<p>For instance, I'd like to compile one file with <code>-mavx2</code> without compiling any other file with that option.</p>



<a name="208154999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208154999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208154999">(Aug 26 2020 at 22:04)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Clone the <code>Build</code>, add the flag and build that one source file separately. It all gets linked together in the end.</p>



<a name="208155268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208155268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208155268">(Aug 26 2020 at 22:07)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> That doesn't help if you're trying to produce a single static library at the end that's findable and usable by other crates, using the <code>DEP_*</code> variables to find it.</p>



<a name="208155406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208155406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208155406">(Aug 26 2020 at 22:09)</a>:</h4>
<p>The static libraries built by <code>cc</code> are automatically embedded into the <code>rlib</code> for the current crate. There shouldn't be a need to access it directly.</p>



<a name="208155428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208155428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208155428">(Aug 26 2020 at 22:09)</a>:</h4>
<p>(Assuming you're running from <code>build.rs</code>)</p>



<a name="208173749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208173749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208173749">(Aug 27 2020 at 02:55)</a>:</h4>
<p>I am, but other crates may use cmake or another build system, and expect to successfully link and run binaries against the built library.</p>



<a name="208173759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208173759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208173759">(Aug 27 2020 at 02:55)</a>:</h4>
<p>Consider something like zlib.</p>



<a name="208173762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208173762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208173762">(Aug 27 2020 at 02:55)</a>:</h4>
<p>Another crate may specifically look for libz.a and try to link it.</p>



<a name="208173806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cc%20and%20arch-specific%20flags%20for%20specific%20source%20files/near/208173806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cc.20and.20arch-specific.20flags.20for.20specific.20source.20files.html#208173806">(Aug 27 2020 at 02:56)</a>:</h4>
<p>Which works, because libz-sys set up search paths properly.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>